<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="池子编号" prop="pond_num">
        <el-select size="small" v-model="queryParams.pond_num" placeholder="请选池子编号" clearable>
          <el-option
              v-for="item in pool_nums"
              :key="item.key"
              :label="item.pond_name"
              :value="item.pond_num"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="查询时间">
        <el-date-picker
            v-model="queryParams.create_times"
            style="width: 212px"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!--增删改查按钮区域-->
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <!-- 数据列表区域-->
    <div id="container"   ref="chinaMapChart" style="height: 300px;width: 48%;float:left;"></div>
    <div id="container3"   ref="chinaMapChart3" style="height: 300px;width: 48%;float:left"></div>
    <div id="container1"  ref="chinaMapChart1" style="height: 240px;width: 48%;float:left;"></div>
    <div id="container2"  ref="chinaMapChart2" style="height: 240px;width: 48%;float:left"></div>
  </div>
</template>
<script>
import "@/assets/styles/robt-bg.css";
import * as echarts from 'echarts';
import {sfnltjxxResult} from "@/api/nssc/aerationresult/aerationresult";
let myChart = null;
let myChart1 = null;
let myChart2 = null;
let myChart3 = null;
export default {
  data() {
    return {
      form: {
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹出层标题
      title: "",
      robot_name: undefined,
      pool_nums:[
        {pond_num:1,pond_name:'R滤格'},{pond_num:2,pond_name:'S滤格'},{pond_num:3,pond_name:'T滤格'},{pond_num:4,pond_name:'U滤格'},
        {pond_num:5,pond_name:'V滤格'},{pond_num:6,pond_name:'W滤格'},{pond_num:7,pond_name:'X滤格'},{pond_num:8,pond_name:'Y滤格'}
      ],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pond_num:"",
        create_times: [this.dealWithTime(new Date()), this.dealWithTime1(new Date())]
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  beforeDestroy() {
    if(myChart != null){myChart.clear();myChart = null;}
    if(myChart1 != null){myChart1.clear();myChart1 = null;}
    if(myChart2 != null){myChart2.clear();myChart2 = null;}
    if(myChart3 != null){myChart3.clear();myChart3 = null;}
  },
  methods: {
    //日期格式化
    dealWithTime(date) {
      let Y = date.getFullYear()
      let M = date.getMonth() + 1 - 0 >= 10 ? Number(date.getMonth()) + 1 : '0' + (Number(date.getMonth()) + 1)
      let D = date.getDate()-6;
      let D1 = D > 10 ? D:"0"+D;
      return Y + '-' + M + '-' + D1
    }, dealWithTime1(date) {
      let Y = date.getFullYear()
      let M = date.getMonth() + 1 - 0 >= 10 ? Number(date.getMonth()) + 1 : '0' + (Number(date.getMonth()) + 1)
      let D = date.getDate() > 10 ? date.getDate():"0"+date.getDate();
      return Y + '-' + M + '-' + D
    },
    getList() {
      sfnltjxxResult(this.queryParams).then(response => {
        let rqs = [];//日期
        let spzs = [];//视频帧数
        let spgjzs = [];//视频关键帧数
        let spsl = [];//视频数量
        let fxsc = [];//分析时长
        let qxgs = [];//缺陷个数
        let fxzsctj = 0;//分析总时长统计
        let fxspzstj = 0;//视频总数统计
        let spzzstj = 0;//视频总帧数统计
        let spgjzztj = 0;//视频关键帧总统计
        let qxgstj = 0;//缺陷个数总统计
        let zcztj = 0;//正常总统计
        let gjztj = 0;//告警总统计
        let zcs = [];//正常数量
        let gjs = [];//告警数量
        if(typeof response.data.sfnltj!='undefined') {
          let size_sfnltj = response.data.sfnltj.length;
          for(let x=0;x < size_sfnltj;x++) {
            rqs[x] = response.data.sfnltj[x].fxsj;//日期
            spzs[x] = (response.data.sfnltj[x].spzs>0?(response.data.sfnltj[x].spzs/10000):0).toFixed(4);//视频帧数
            spgjzs[x] = response.data.sfnltj[x].gjzs;//视频关键帧数
            spsl[x] = response.data.sfnltj[x].spsl;//视频数量
            fxsc[x] = response.data.sfnltj[x].fxsc;//分析时长
            qxgs[x] = response.data.sfnltj[x].qxgs;//缺陷个数
            fxzsctj=fxzsctj + parseInt(response.data.sfnltj[x].fxsc);
            fxspzstj=fxspzstj + parseInt(response.data.sfnltj[x].spsl);
            spzzstj=spzzstj + parseInt(response.data.sfnltj[x].spzs);
            spgjzztj=spgjzztj + parseInt(response.data.sfnltj[x].gjzs);
            zcztj=zcztj + parseInt(response.data.sfnltj[x].zc);
            gjztj=gjztj + parseInt(response.data.sfnltj[x].gj);
            qxgstj= qxgstj+parseInt(response.data.sfnltj[x].qxgs);
            zcs[x] = response.data.sfnltj[x].zc;
            gjs[x] = response.data.sfnltj[x].gj;
          }
          if(size_sfnltj > 0 ) {
            this.sfnlfx(rqs, spzs, spgjzs,spsl,fxsc,qxgs);//算法能力分析
            this.sfbjfx(rqs, zcs, gjs);//告警能力分析
            this.sftjxx(fxzsctj,fxspzstj,spzzstj,spgjzztj,qxgstj);//算法统计信息总数
            this.spfxtj(zcztj,gjztj);//视频分析统计
          } else {
            this.sfnlfx([0], [0], [0], [0], [0], [0]);//算法能力分析
            this.sfbjfx([0], [0], [0]);//告警能力分析
            this.sftjxx(0, 0, 0, 0,0);//算法统计信息总数
            this.spfxtj(0, 0);//视频分析统计
          }
        } else {
          if(myChart != null) myChart.dispose()//销毁echarts
          if(myChart1 != null) myChart1.dispose()//销毁echarts
          if(myChart2 != null) myChart2.dispose()//销毁echarts
          if(myChart3 != null) myChart3.dispose()//销毁echarts
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.pond_num="";
      this.queryParams.create_times= [this.dealWithTime(new Date()), this.dealWithTime1(new Date())];
      this.handleQuery();
    },
    /* 算法能力分析*/
    sfnlfx(rqs, spzs, spgjzs,spsl,fxsc,qxgs){
      setTimeout(() => {
        myChart = echarts.init(this.$refs.chinaMapChart)
        let option;
        const labelOption = {
          show: true,
          position:'top',
          distance: 15,
          align:'left',
          verticalAlign: 'middle',
          color: '#00d3ff',
          rotate: 90,
          fontsize:16,
          //formatter: '{c}  {name|{a}}',
          formatter: '{c}',
          fontSize: 10,
          rich: {
            name: {}
          }
        };
        option = {
          title: {
            text: '能力柱状图',
            y:'top',
            x:'left',
            textStyle: {
              color: '#2b49a9'
            }
          },
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'shadow'
            }
          },
          color: ['#058abb', '#1d6ee8', '#cc8a0e', '#0aa95b','#ab18b0'],
          legend: {
            top: '7%',
            data: ['分析时长', '视频帧数(万)', '视频关键帧数', '分析视频数量','缺陷数量'],
            textStyle: {
              color: "#9d9e9f"
            }
          },
          toolbox: {
            show: true,
            orient: 'vertical',
            left: 'right',
            top: 'center',
            feature: {
              mark: { show: true },
             /* dataView: { show: true, readOnly: false },
              magicType: { show: true, type: ['line', 'bar', 'stack'] },
              restore: { show: true },
              saveAsImage: { show: true }*/
            }
          },
          xAxis: [
            {
              type: 'category',
              axisLine: {
                show: true, // 不显示坐标轴线
                lineStyle: {
                  color: '#00ccff', //x轴的颜色
                },
              },
              //横坐标值颜色
              axisLabel: {
                show: true,
                textStyle: {
                  color: '#7287ab'
                }
              },
              splitLine: {
                show: false // 不显示网格线
              },
              axisTick: { show: false },
              data:rqs
            }
          ],
          yAxis: [
            {
              type: 'value',
              axisTick: {
                show: true,  //刻度线
              },
              axisLabel: {
                show: true, //隐藏刻度值
              },
              axisLine: {
                show: true,//隐藏y轴
                lineStyle: {
                  color: '#00ccff', //x轴的颜色
                },
              } ,
              splitLine: {
                show: false // 不显示网格线
              },
            }
          ],
          series: [
            {
              barWidth: '18%',
              name: '分析时长',
              type: 'bar',
              barGap: 0,
              label: labelOption,
              emphasis: {
                focus: 'series'
              },
              data: fxsc,
              itemStyle: {
                color: '#058abb' // 设置曲线颜色为红色（十六进制）
              },
            },
            {
              barWidth: '18%',
              name: '视频帧数(万)',
              type: 'bar',
              label: {
                show: true,
                position:'top',
                distance: 15,
                align:'left',
                verticalAlign: 'middle',
                color: '#00d3ff',
                rotate: 90,
                fontsize:16,
                formatter: '{c}万',
                fontSize: 10,
                rich: {
                  name: {}
                }
              },
              emphasis: {
                focus: 'series'
              },
              data:spzs,
              itemStyle: {
                color: '#1d6ee8' // 设置曲线颜色为红色（十六进制）
              },
            },
            {
              barWidth: '18%',
              name: '视频关键帧数',
              type: 'bar',
              label: labelOption,
              emphasis: {
                focus: 'series'
              },
              data: spgjzs,
              itemStyle: {
                color: '#cc8a0e' // 设置曲线颜色为红色（十六进制）
              },
            },
            {
              barWidth: '18%',
              name: '分析视频数量',
              type: 'bar',
              label: labelOption,
              emphasis: {
                focus: 'series'
              },
              data: spsl,
              itemStyle: {
                color: '#0aa95b' // 设置曲线颜色为红色（十六进制）
              },
            },
            {
              barWidth: '18%',
              name: '缺陷数量',
              type: 'bar',
              label: labelOption,
              emphasis: {
                focus: 'series'
              },
              data: qxgs,
              itemStyle: {
                color: '#ab18b0' // 设置曲线颜色为红色（十六进制）
              },
            }
          ],dataZoom: [
          {
            fillerColor:'#0e2e79',
            borderColor:'#1c44a2',
            height:20,
            //  bottom:10,
            type: 'inside',
            startValue: 0,
            endValue: 4
          },
          {
            fillerColor:'#0e2e79',
            borderColor:'#1c44a2',
            height:20,
            //  bottom:10,
            startValue: 0,
            endValue: 4
          }
        ]
        };
        if (option && typeof option === 'object') {
          myChart.setOption(option);
        }
        window.addEventListener("resize", () => {
          if(myChart!=null)myChart.resize();
        });//同比缩放
      }  , 1);
    },//算法告警分析
    sfbjfx(rqs, zcs, gjs){
      setTimeout(() => {
        myChart3 = echarts.init(this.$refs.chinaMapChart3)
        let option3;
        const labelOption = {
          show: true,
          position:'top',
          distance: 15,
          align:'left',
          verticalAlign: 'middle',
          color: '#00d3ff',
          rotate: 90,
          fontsize:16,
          /*formatter: '{c}  {name|{a}}',*/
          formatter: '{c}',
          fontSize: 10,
          rich: {
            name: {}
          }
        };
        option3 = {
          title: {
            text: '告警柱状图',
            y:'top',
            x:'left',
            textStyle: {
              color: '#2b49a9'
            }
          },
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'shadow'
            }
          },
          color: ['#02678c', '#2b2ecb', '#cc8a0e'],
          legend: {
            top: '7%',
            data: [ '正常','告警'],
            textStyle: {
              color: "#9d9e9f"
            }
          },
          toolbox: {
            show: true,
            orient: 'vertical',
            left: 'right',
            top: 'center',
            feature: {
              mark: { show: true },
              /* dataView: { show: true, readOnly: false },
               magicType: { show: true, type: ['line', 'bar', 'stack'] },
               restore: { show: true },
               saveAsImage: { show: true }*/
            }
          },
          xAxis: [
            {
              type: 'category',
              axisLine: {
                show: true, // 不显示坐标轴线
                lineStyle: {
                  color: '#00ccff', //x轴的颜色
                },
              },
              //横坐标值颜色
              axisLabel: {
                show: true,
                textStyle: {
                  color: '#7287ab'
                }
              },
              splitLine: {
                show: false // 不显示网格线
              },
              axisTick: { show: false },
              data:rqs
            }
          ],
          yAxis: [
            {
              type: 'value',
              axisTick: {
                show: true,  //刻度线
              },
              axisLabel: {
                show: true, //隐藏刻度值
              },
              axisLine: {
                show: true,//隐藏y轴
                lineStyle: {
                  color: '#00ccff', //x轴的颜色
                },
              } ,
              splitLine: {
                show: false // 不显示网格线
              },
            }
          ],
          series: [
            {
              barWidth: '18%',
              name: '正常',
              type: 'bar',
              label: labelOption,
              emphasis: {
                focus: 'series'
              },
              data:zcs,
              itemStyle: {
                color: '#07ad68' // 设置曲线颜色为红色（十六进制）
              },
            },
            {
              barWidth: '18%',
              name: '告警',
              type: 'bar',
              label: labelOption,
              emphasis: {
                focus: 'series'
              },
              data: gjs,
              itemStyle: {
                color: '#a8350b' // 设置曲线颜色为红色（十六进制）
              },
            }
          ],dataZoom: [
            {
              fillerColor:'#0e2e79',
              borderColor:'#1c44a2',
              height:20,
              //  bottom:10,
              type: 'inside',
              startValue: 0,
              endValue: 4
            },
            {
              fillerColor:'#0e2e79',
              borderColor:'#1c44a2',
              height:20,
              //  bottom:10,
              startValue: 0,
              endValue: 4
            }
          ]
        };
        if (option3 && typeof option3 === 'object') {
          myChart3.setOption(option3);
        }
        window.addEventListener("resize", () => {
          if(myChart3!=null)myChart3.resize();
        });//同比缩放
      }  , 1);
    },//算法统计信息总数
    sftjxx(fxzsctj,fxspzstj,spzzstj,spgjzztj,qxgstj) {
      setTimeout(() => {
        myChart1 = echarts.init(this.$refs.chinaMapChart1)
        let option1;
        option1 = {
          title: {
            text: '能力统计',
            y:'top',
            x:'left',
            textStyle: {
              color: '#2b49a9'
            }
          },
          cursor: 'default',//取消鼠标变成小手
          xAxis: {
            type: 'category',
            axisLine: {
              show: false, // 不显示坐标轴线
              lineStyle: {
                color: '#00ccff', //x轴的颜色
              },
            },
            //横坐标值颜色
            axisLabel: {
              show: true,
              textStyle: {
                color: '#7287ab'
              }
            },
            splitLine: {
              show: false // 不显示网格线
            },
            axisTick: { show: false },
            data: ['分析总时长', '视频总帧数', '关键帧总数', '分析视频总数', '缺陷总数']
          },
          yAxis: {
            show: false, // 隐藏Y轴
            type: 'value',
            axisTick: {
              show: true,  //刻度线
            },
            axisLabel: {
              show: true, //隐藏刻度值
              fontSize: 10 // 设置 y 轴字体大小为16
            },
            axisLine: {
              show: true,//隐藏y轴
              lineStyle: {
                color: '#00ccff', //x轴的颜色
              },
            } ,
            splitLine: {
              show: false // 不显示网格线
            },
          },
          series: [
            {
              data: [
                {
                  value: fxzsctj,
                  itemStyle: {
                    color: '#058abb'
                  },
                  type: 'bar',
                  barWidth: '2%',
                  label: {
                    show: true, // 显示数值
                    position: 'top' // 数值显示的位置
                  }
                },
                {
                  value: fxspzstj,
                  itemStyle: {
                    color: '#1d6ee8'
                  },
                  type: 'bar',
                  barWidth: '2%',
                  label: {
                    show: true, // 显示数值
                    position: 'top' // 数值显示的位置
                  }
                },
                {
                  value:spgjzztj,
                  itemStyle: {
                    color: '#cc8a0e'
                  },
                  type: 'bar',
                  barWidth: '2%',
                  label: {
                    show: true, // 显示数值
                    position: 'top' // 数值显示的位置
                  }
                },
                {
                  value: spgjzztj>0?(spgjzztj/10000).toFixed(4):0,
                  itemStyle: {
                    color: '#0aa95b'
                  },
                  type: 'bar',
                  barWidth: '2%',
                  label: {
                    show: true, // 显示数值
                    formatter: '{c}万', // {c}为当前数值
                    position: 'top' // 数值显示的位置
                  }
                },
                {
                  value: qxgstj,
                  itemStyle: {
                    color: '#ab18b0'
                  },
                  type: 'bar',
                  barWidth: '2%',
                  label: {
                    show: true, // 显示数值
                    position: 'top' // 数值显示的位置
                  }
                },
              ],
              type: 'bar'
            }
          ]
        };
        if (option1 && typeof option1 === 'object') {
          myChart1.setOption(option1);
        }
        window.addEventListener("resize", () => {
          if(myChart1!=null)myChart1.resize();
        });//同比缩放
      } , 1);
    }, //视频分析统计
    spfxtj(zcztj,gjztj) {
      setTimeout(() => {
        myChart2 = echarts.init(this.$refs.chinaMapChart2)
        let option2;
        option2 = {
          title: {
            text: '告警数量统计',
            y:'top',
            x:'left',
            textStyle: {
              color: '#2b49a9'
            }
          },
          tooltip: {
            trigger: 'item'
          },
          legend: {
            top: '8%',
            left: 'center',
            textStyle: {
              color: "#9d9e9f"
            }
          },
          series: [
            {
              color: ['#07ad68', '#cc410e'],
              name: '',
              type: 'pie',
              radius: ['50%', '70%'],
              center: ['50%', '60%'],
              // adjust the start and end angle
              startAngle: 180,
              endAngle: 360,
              data: [
                {value: zcztj, name: '正常数量'+'（'+zcztj+'）'},
                {value: gjztj, name: '告警数量'+'（'+gjztj+'）'},
              ]
            }
          ]
        };

        if (option2 && typeof option2=== 'object') {
          myChart2.setOption(option2);
        }
        window.addEventListener("resize", () => {
          if (myChart2 != null) myChart2.resize();
        });//同比缩放
      } , 1);
    }
  }
};
</script>
<style rel="stylesheet/scss" lang="scss">
/**列表添加垂直隐藏滚动条**/
.tabled{
  height: 550px;
  overflow: hidden;
  overflow-y: scroll;
}
.tabled::-webkit-scrollbar {
  width: 0 !important;
  height: 0 !important;
}
</style>
